package channels4java.exceptions;

public class Channels4JavaException extends Exception {

	private static final long serialVersionUID = 1L;
	
	private ErrorType error;
	public static enum ErrorType
	{
		INPUT_OUTPUT, // the generic I/O error...
		UNKNOWN_HOST, // when a specified host name or IP address is not valid or unknown
		INVALID_PORT, // when a specified port number is wrong (typically less than zero)
		BIND_ERROR, // typically the port is in use
		CONNECTION_ERROR, // typically the connection was refused remotely (maybe there is no process listening at the given IP/port)
		NO_ROUTE_TO_HOST, // typically the remote host cannot be reached because of an intervening firewall, or if an intermediate router is down
		PORT_UNREACHABLE, // signals that an ICMP Port Unreachable message has been received on a connected datagram.
		
		INVALID_MESSAGE_FORMAT, // used when a message is being constructed from it's serialized form and an error in the message syntax occurs
		INVALID_MESSAGE_TYPE, // used when a message is received with the wrong type
		SESSION_REJECTED, // used to indicate that a session is rejected
		
		HANDSHAKE_ERROR, // identifies an error caused in an handshake process
		
		INVALID_CERTIFICATE_TYPE, // when the suplied certificate type is not supported
		CERTIFICATE_PARSE_ERROR, // when an error occured when parsing the certificate. Must be DER-encoded and may be supplied in binary or printable (Base64) encoding
		CERTIFICATE_NOT_FOUND, // when the certificate file was not found
		CERTIFICATE_ENCODING_ERROR, // error in the certificate encoding
	}

	public Channels4JavaException() {
	}

	public Channels4JavaException(String message) {
		super(message);
	}

	public Channels4JavaException(Throwable cause) {
		super(cause);
	}

	public Channels4JavaException(String message, Throwable cause) {
		super(message, cause);
	}
	
	public Channels4JavaException(ErrorType error, String message, Throwable cause)
	{
		super(message, cause);
		this.setErrorType(error);
	}

	public ErrorType getErrorType()
	{
		return this.error;
	}
	
	public void setErrorType(ErrorType error)
	{
		if(error == null) throw new IllegalArgumentException("invalid error type");
		
		this.error = error;
	}
}
